Better closure requirement propagation V2#154271
Better closure requirement propagation V2#154271LorrensP-2158466 wants to merge 3 commits intorust-lang:mainfrom
Conversation
try_promote_type_test_subject + add a test.
Yeah, let me write down my thoughts here. There are actually multiple things here. We can prove What we currently do on stable and what I didn't even think of, is that if we have Separately, if we have Now, if we know that we'll separately propagate We do have access to Separately, we could handle type tests as a two step pass. First collect all type tests which have a single possible candidate, then go through all the ones with multiple options and check whether one of the options is already part of the list of definitely required type tests. Could also do that separately/not handle that part for now 🤷 |
|
Thanks for the explanation, i understand now.
I am with you here, that's what this PR is currently doing right?
Yes right, I was thinking in the same direction, this is the part where i am stuck because a clean solution didn't come to me. I only came up with the following myself:
But this seems a bit unnatural to me, i prefer the other one:
I find that this equates to finding the "minimal required" type tests. Which we seem to resort to in these closure propagation pr's.
I will try both solutions anyway, you never know :). i'll create separate branches in my fork and create a channel on zullip to discuss them. If you want it done in another way, lmk! |
This comment has been minimized.
This comment has been minimized.
05a43d7 to
657862c
Compare
Fix in question: We only propagate `T: 'ub` requirements when 'ub actually outlives the lower bounds of the type test. If none of the non-local upper bounds outlive it, then we propagate all of them.
This comment has been minimized.
This comment has been minimized.
657862c to
d27d602
Compare
Yeah, nevermind, the 2-phase way is much easier to implement and is more logical (at least to me :)). When trying to define the problem it reminded me of Unit Propagation. Basically given a boolean expression in conjunctive normal form (i.e boolean expressions with AND operators between them), try to simplify the expressions by "propagating unit expressions". Filtering these OR requirements in conjunctive normal form can be reduced to this Unit Propagation problem, but it is simpler, the subexpressions only contain OR operators, so the full expression is true if at least one unit is true. Thus, Given your example:
Then the full requirement (expression) is This can be done in 1 pass, as the code does. And it compiles your harder example successfully. @rustbot ready |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Fixes #154267
Unblocks #151510.
We only propagate
T: 'ubrequirements when'ubactually outlives the lower bound of the type test. If none of the non-local upper bounds outlive the lower bound, then we propagate all of them.r? @lcnr